<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./site/public/user/_pre.php, $Author:  $ */


//load target user
$oReq = &App::getRequest();

if ( $iRedirectId = $oReq->get('redirectid') )
{
	$oDb = &Database::get();
	$aUserDetail = $oDb->getRow("SELECT user FROM ". App::getT('user') ." WHERE id = '". $oDb->escape($iRedirectId) ."'");
	App::gotoUrl('public.user', array('name' => $aUserDetail['user']));
}

$sUser = $oReq->get('name');

if (!$sUser)
{
    App::gotoUrl('public');
}

$oSrvAcc = &App::getModuleService('Account', 'Account');
/* @var $oSrvSec PhpFox_Mod_Account_ServiceAccount */
$oSrvSec = &App::getModuleService('Account', 'Security');
/* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */

$oUser = &$oSrvAcc->getUserDetails($sUser);

if ( !isset($oUser->aData['user']) )
{
    App::gotoUrl('public.notfound.user_'. $sUser .'');
}

//get current user
$oCurrUser = $oSrvSec->getCurrentUser();

$bIsOwner = ($oCurrUser && ($oCurrUser->aData['id'] == $oUser->aData['id']));

if(!$bIsOwner)
{   
	$bBlockUser=$oSrvSec->checkMyBlockUsers($oCurrUser,$sUser);
}

if (isset($bBlockUser) && $bBlockUser) 
{
	App::gotoUrl('public.notfound', array('block' => $oUser->aData['user']));
}

if ($oUser->aData['is_banned']) 
{
	App::gotoUrl('public.notfound', array('user' => $oUser->aData['user']));
}

$sProfilePerm = $oSrvSec->getPerm('profile');
if (('no'==$sProfilePerm) && (! $bIsOwner))
{
	$_SESSION['redirect_profile_url'] = App::getPage();
	App::gotoUrl('public.denied');
}

if (!$bIsOwner && $oCurrUser)
{
    $oSrvLog = &App::getModuleService('Log', 'Log');
    /* @var $oSrvLog PhpFox_Mod_Log_ServiceLog */
    $oSrvLog->addProfileView($oCurrUser, $oUser);
}

//perform  check on blocked/not-blocked
$bIsBlocked = false;
if (!$oSrvSec->isStaff() && !$bIsOwner && ('public.user.blocked' != App::getPageName()))
{
    $oSrvBlock = &App::getModuleService('Account', 'Block');
    /* @var $oSrvBlock PhpFox_Mod_Account_ServiceBlock */
    $bIsBlocked = $oSrvBlock->isBlocked($oUser, $oCurrUser);
    if (!$bIsBlocked)
    {
        //check for 'friends only' setting
        if ($oUser->aData['friends_only'])
        {

            $oSrvFriend = App::getModuleService('Account', 'Friends');
            /* @var $oSrvFriend PhpFox_Mod_Account_ServiceFriends */
            $bIsBlocked = !$oSrvFriend->isFriend($oCurrUser, $oUser);
        }
    }

    if ( $bIsBlocked )
    {
		App::gotoUrl('public.user.blocked', array('name'=>$sUser,'friend'=>'false'));
    }
}

//create tabs menu
$aMenuItems = array();
$aMenuItems['public.user'] = App::format('menu.profile.user');
if ($oSrvSec->checkAccess('gallery', '', false))
{
	$aMenuItems['public.user.gallery'] = App::format('menu.profile.gallery');
}
if ($oSrvSec->checkAccess('blogs', '', false))
{
	$aMenuItems['public.user.blogs'] = App::format('menu.profile.blogs');
}
$aMenuItems['public.user.guestbook'] = App::format('menu.profile.guestbook');
$aMenuItems['public.user.friends']   = App::format('menu.profile.friends');
$aMenuItems['public.user.favorites'] = App::format('menu.profile.favorites');

if ( $oSrvSec->checkAccess('video', '', false) )
{
	$aMenuItems['public.user.videos'] = App::format('menu.profile.videos');
}

if (App::getSetting('profile_mode'))
{
    $aMenuItems['public'] = array
    (
        'params' => array(),
        'title'  => App::format('menu.profile.home'),
    );
}

$aParams = array(
	'sTemplate' => 'TabbedMenu',
    'aMenuItems' => $aMenuItems,
    'aParams'    => array('name'=>$oUser->aData['user']),
    'sTitle'     => $oUser->aData['user'],
);

$oCompMenu = App::getModuleComponent('Menu', 'Menu', $aParams);
$srcTabbedMenu = $oCompMenu->process();

$aUser =& $oUser->aData;

$oTpl = &App::getTemplate();

$oStyle = App::getModuleComponent('Site', 'StyleReplace', array('oUser' => $oUser));

$oTpl->assignSrc(array(
	'srcTabbedMenu' => $srcTabbedMenu,
	'bIsOwner'      => $bIsOwner,
	'sSiteSlogan'   => App::getSetting('site_name'),
	'bHideHeader'   => !App::getSetting('profile_mode'),
    'aUser'         => $aUser,
    'bShowComments' => App::getSetting('profile_display_comment'),
    'oUser'         => $oUser,
    'sPathTransJs'  => App::makeJSPathTranslatedValue(),
    'bShutDown'     => App::getSetting('site_shutdown'),
    'sUserStyle'    => $oStyle->process()
));

$oTpl->assignSrc(array
(
	'plugin_user_left' => phpFoXPlugins::create_content('user_left'),
	'plugin_user_right' => phpFoXPlugins::create_content('user_right'),
));

?>